from datetime import datetime
from typing import Optional, Literal

from pydantic import BaseModel, Field, field_validator


class HistoryResponse(BaseModel):
    """股票历史数据模型"""
    time: str = Field(..., title="日期", json_schema_extra={"example": "2025-05-26"})
    symbol: str = Field(title="股票代码")
    open: float = Field(title="开盘价")
    close: float = Field(title="收盘价")
    high: float = Field(title="最高价")
    low: float = Field(title="最低价")
    volume: float = Field(title="成交量")
    turnover: float = Field(title="成交额")
    amplitude: float = Field(title="振幅")
    changePercent: float = Field(title="涨跌幅")
    changeAmount: float = Field(title="涨跌额")
    turnoverRate: float = Field(title="换手率")


class RealtimeResponse(BaseModel):
    """实时行情数据模型"""
    # time: datetime = Field(..., title="时间", description="YYYY-mm-DD HH-MM-DD")
    time: int = Field(..., title="时间", json_schema_extra={"example": 1748400913492})
    open: float = Field(..., title="开盘价")
    close: float = Field(..., title="收盘价")
    high: float = Field(..., title="最高价")
    low: float = Field(..., title="最低价")
    volume: float = Field(..., title="成交量(手)")
    turnover: float = Field(..., title="成交额")
    avg_price: float = Field(..., title="均价")

    # class Config:
    #     json_schema_extra = {
    #         "example": {
    #             "time": "2025-05-26 09:30:00",
    #             "open": 12.46,
    #             "close": 12.46,
    #             "high": 12.46,
    #             "low": 12.46,
    #             "volume": 412,
    #             "turnover": 513352,
    #             "avg_price": 12.46
    #         }
    #     }


class QuoteResponse(BaseModel):
    """股票行情数据模型"""
    sell_5: float = Field(..., title="第五档卖单价")
    sell_5_vol: float = Field(..., title="第五档卖单量")
    sell_4: float = Field(..., title="第四档卖单价")
    sell_4_vol: float = Field(..., title="第四档卖单量")
    sell_3: float = Field(..., title="第三档卖单价")
    sell_3_vol: float = Field(..., title="第三档卖单量")
    sell_2: float = Field(..., title="第二档卖单价")
    sell_2_vol: float = Field(..., title="第二档卖单量")
    sell_1: float = Field(..., title="第一档卖单价(卖一价)")
    sell_1_vol: float = Field(..., title="第一档卖单量(卖一量)")

    buy_1: float = Field(..., title="第一档买单价(买一价)")
    buy_1_vol: float = Field(..., title="第一档买单量(买一量)")
    buy_2: float = Field(..., title="第二档买单价")
    buy_2_vol: float = Field(..., title="第二档买单量")
    buy_3: float = Field(..., title="第三档买单价")
    buy_3_vol: float = Field(..., title="第三档买单量")
    buy_4: float = Field(..., title="第四档买单价")
    buy_4_vol: float = Field(..., title="第四档买单量")
    buy_5: float = Field(..., title="第五档买单价")
    buy_5_vol: float = Field(..., title="第五档买单量")

    # Real-time Trading Data
    last_price: float = Field(..., title="最新成交价", json_schema_extra={"example": 11.63})
    avg_price: float = Field(..., title="均价", )
    change_percent: float = Field(..., title="涨幅(百分比)", )
    change_amount: float = Field(..., title="涨跌(绝对值)", )
    volume: float = Field(..., title="总成交量(手)股）", )
    turnover: float = Field(..., title="成交金额(元)", )
    turnover_rate: float = Field(..., title="换手率(百分比)", )
    volume_ratio: float = Field(..., title="量比", )

    # OHLC Data
    high: float = Field(..., title="当日最高价", )
    low: float = Field(..., title="当日最低价", )
    open: float = Field(..., title="今开价", )
    prev_close: float = Field(..., title="昨收价", )
    upper_limit: float = Field(..., title="涨停价", )
    lower_limit: float = Field(..., title="跌停价", )

    # Market Activity
    bid_volume: float = Field(..., title="外盘(主动买入量)", )
    ask_volume: float = Field(..., title="内盘(主动卖出量)", )

    timestamp: int = Field(..., title="数据时间戳", json_schema_extra={"example": 1748400913492})
